<?php


namespace app\common\model;


use think\Model;

class ProjectModel extends Model
{
    protected $name = 'project';


    public function getIndexList($cate_id,$limit)
    {
        $where = [
            'status' => 1,
            'cate_id' => ['in',$cate_id],
            'index' => 1,
        ];
        return $this
            ->where($where)
            ->whereNull('deletetime')
            ->order([
                'weigh' => 'asc',
            ])
            ->limit($limit)
            ->select();
    }

    public function getAboutList()
    {
        $where = [
            'status' => 1,
            'cate_id' => 1,
        ];
        return $this
            ->where($where)
            ->whereNull('deletetime')
            ->order([
                'weigh' => 'asc',
            ])
            ->select();
    }


    public function getProjectRecommend($cate_id = 0)
    {
        $where = [
            'status' => 1,
            'recommend' => 1,
        ];
        if($cate_id > 0){
            $where['cate_id'] = $cate_id;
        }
        return $this
            ->where($where)
            ->whereNull('deletetime')
            ->order([
                'weigh' => 'asc',
            ])
            ->find();
    }

    public function getPageList($cate_id = 0,$page = 1,$limit = 6)
    {
        $where = [
            'status' => 1,
        ];
        if($cate_id > 0){
            $where['cate_id'] = $cate_id;
        }
        return $this
            ->where($where)
            ->whereNull('deletetime')
            ->order([
                'weigh' => 'asc',
            ])
            ->paginate($limit,false, ['page' => $page]);
    }

    public function getDetail($id)
    {
        $data = $this->get($id);
        $data->images = MoreImageDomain($data->images);
        return $data;
    }
}